package com.xiaobao.controller;

import com.xiaobao.pojo.Result;
import com.xiaobao.pojo.UserInfo;
import com.xiaobao.service.UserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;


//用户详情控制器
@RestController
public class UserInfoController {

    private static final Logger log = LoggerFactory.getLogger(UserInfoController.class);
    private final UserInfoService userInfoService;

    public UserInfoController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    //修改用户详细信息
    @PostMapping("/updateUserInfo")
    public Result<UserInfo> UpdateUserInfo(@RequestBody UserInfo userInfo) {
        log.info("修改用户信息");
        log.info(userInfo.toString());
        if (userInfoService.updateUserInfo(userInfo)) {
            return new Result<>(true, 200, "修改成功", userInfo);
        }
        return new Result<>(false, 400, "修改失败", userInfo);
    }//测试成功

    //删除用户详细信息
    @DeleteMapping("/deleteUserInfo/{id}")
    public Result<UserInfo> deleteUserInfo(@PathVariable String id) {
        if (userInfoService.deleteUserInfo(id)) {
            return new Result<>(true, 200, "删除成功", null);
        }
        return new Result<>(false, 400, "删除失败", null);
    }
}
